# 数据库是否开启归档模式 declare -l enable_arch=true # 仅配置操作系统,默认值为 N,包括配置操作系统以及解压软件安装包 declare -u only_conf_os=N # 定义一个用于保存 root 用户需要设置 SSH 信任的 IP 地址 declare -a ssh_ips # 定义用于保存心跳 IP 的关联数组 declare -A rac_priv_ips
脚本并未适配 bash-4 以下版本,所以未曾考虑命令不支持的问题。
原因分析
在我的 rhel8 主机上查看这 3 个参数的含义:
1 2 3 4
Options whichset attributes: -A to make NAMEs associative arrays (if supported) -l to convert NAMEs to lower case on assignment -u to convert NAMEs to upper case on assignment
## shell 提供关联数组变量,也就是对 -A 参数的支持 +ii. The shell provides associative array variables, with the appropriate + support to create, delete, assign values to, and expand them. + # 对 declare 命令新增了 -l 和 -u 命令 +jj. The `declare' builtin now has new -l (convert value to lowercase upon + assignment) and -u (convert value to uppercase upon assignment) options. + There is an optionally-configurable -c option to capitalize a value at + assignment.
## bash-4.0-rc1 +n. The -p option to `declare' now displays all variable values and attributes + (or function values and attributes if used with -f). +jj. The `declare'builtin now has new -l (convert value to lowercase upon + assignment) and -u (convert value to uppercase upon assignment) options. + There is an optionally-configurable -c option to capitalize a value at + assignment.
## bash-4.2 +e. declare/typeset has a new `-g' option, which creates variables in the + global scope even when run in a shell function. ## bash-4.4 +f. The `-p' option to declare and similar builtins will display attributes for + named variables even when those variables have not been assigned values + (which are technically unset).
+p. Bash no longer attempts to perform compound assignment if a variable on the + rhs of an assignment statement argument to `declare' has the form of a + compound assignment (e.g., w='(word)' ; declare foo=$w); compound + assignments are accepted if the variable was already declared as an array, + but with a warning. + +q. The declare builtin no longer displays array variables using the compound + assignment syntax with quotes; that will generate warnings when re-used as + input, and isn't necessary.
## bash-5.0 +aa. The `@A' variable transformation now prints a declare command that sets a + variable's attributes if the variable has attributes but is unset. + +bb. `declare' and `local' now have a -I option that inherits attributes and + value from a variable with the same name at a previous scope.
## bash-5.2 +bb. Array references using `@' and `*' that are the value of nameref variables + (declare -n ref='v[@]' ; echo$ref) no longer cause the shell to exitif + set -u is enabled and the array (v) is unset.
+gg. Since there is no `declare -' equivalent of `local -', make sure to use + `local -' in the output of `local -p'.